package com.sikao.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.ProductIndexListBeans;
import com.sikao.app.utils.Utils;

import java.util.List;


/**
 * Created by y50 on 2016/5/23.
 */
public class ProductExtraInfAdapter extends BaseAdapter {

	private Context context;
	private List<ProductIndexListBeans> productIndexBeanList;

	public ProductExtraInfAdapter(Context context, List<ProductIndexListBeans> productIndexBeanList) {
		this.context = context;
		this.productIndexBeanList = productIndexBeanList;
	}


	@Override
	public int getCount() {
		return productIndexBeanList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.product_index_list_item1, null);
			convertView.setTag(new ViewHolder(convertView));
		}
		//if (position == 0 || position == 3)
		//((ProductIndexBean)getItem(position)).setName("大富科技的谁离开房间卡时间段付款了我也不知道这是什么情况啊就将计就计");
		initializeViews(productIndexBeanList.get(position), (ViewHolder) convertView.getTag());

		return convertView;
	}

	private void initializeViews(ProductIndexListBeans productIndexBean, ViewHolder viewHolder) {
		viewHolder.keytv1.setText(productIndexBean.getBeans().get(0).getName());
		viewHolder.valuetv1.setText(productIndexBean.getBeans().get(0).getDefault_value_toString());
		Utils.showLog("====招标的产品指标" + productIndexBean.getBeans().get(0).getDefault_value_toString());
		if (productIndexBean.getBeans().size() > 1) {
			viewHolder.keytv2.setText(productIndexBean.getBeans().get(1).getName());
			viewHolder.valuetv2.setText(productIndexBean.getBeans().get(1).getDefault_value_toString());
			Utils.showLog("====招标的产品指标" + productIndexBean.getBeans().get(1).getDefault_value_toString());
		}else {
			viewHolder.tv.setVisibility(View.INVISIBLE);
		}

	}

	public class ViewHolder {
		public final TextView keytv1;
		public final TextView valuetv1;
		public final TextView keytv2;
		public final TextView tv;
		public final TextView valuetv2;
		public final View root;

		public ViewHolder(View root) {
			keytv1 = (TextView) root.findViewById(R.id.key_tv1);
			valuetv1 = (TextView) root.findViewById(R.id.value_tv1);
			keytv2 = (TextView) root.findViewById(R.id.key_tv2);
			tv = (TextView) root.findViewById(R.id.tv);
			valuetv2 = (TextView) root.findViewById(R.id.value_tv2);
			this.root = root;
		}
	}
}
